package com.prs.crm.dao.flow.impl;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.context.AppContext;
import com.prs.crm.dao.flow.FlowNodePersonDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.crm.CustomerSource;
import com.prs.crm.domain.doc.Document;
import com.prs.crm.domain.flow.FlowNodePerson;
import com.prs.crm.domain.flow.WorkFlow;
import com.prs.crm.domain.flow.WorkFlowNode;

/** 
 * <p>Copyright: Copyright (c) 2012</p>
 * @author JohnLan 
 * E-mail:JohnMr.Lan@foxmail.com 
 * @version 创建时间：2012-7-23 下午05:42:05 
 * 
 * 类说明 
 */

public class FlowNodePersonDaoImpl extends BaseDaoImpl<FlowNodePerson>
		implements FlowNodePersonDao {
	
	private FlowNodePerson flowNodePerson;
	public FlowNodePerson getFlowNodePerson() {
		return flowNodePerson;
	}

	public void setFlowNodePerson(FlowNodePerson flowNodePerson) {
		this.flowNodePerson = flowNodePerson;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<WorkFlowNode> getWorkFlowNode(final WorkFlow workflow) {
		
//		Criteria criteria = this.getSession().createCriteria(WorkFlowNode.class);
//		criteria.add(Restrictions.eq("flow",36));
//		return criteria.list();
		
		
		return (List<WorkFlowNode>)this.getHibernateTemplate().executeFind(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(WorkFlowNode.class);
				criteria.add(Restrictions.eq("flow", workflow));
				return criteria.list();
			}
			
		});
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FlowNodePerson> getFlowNodePerson(final WorkFlow workFlow) {
		Criteria criteria=this.getSession().createCriteria(FlowNodePerson.class);
		criteria.add(Restrictions.eq("workFlow", workFlow));
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FlowNodePerson> getFlowNodePersons(WorkFlowNode workFlowNode) {
		Criteria criteria=this.getSession().createCriteria(FlowNodePerson.class);
		criteria.add(Restrictions.eq("workFlowNode", workFlowNode));
		criteria.add(Restrictions.eq("nodePersonName", AppContext.getAccountContext().currentUser()));
		criteria.add(Restrictions.eq("state", 0));
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FlowNodePerson> getFlowNodePersons1(
			FlowNodePerson flowNodePerson) {
		Criteria criteria=this.getSession().createCriteria(FlowNodePerson.class);
		criteria.add(Restrictions.eq("nodePersonName", AppContext.getAccountContext().currentUser()));
		criteria.add(Restrictions.eq("state", 0));
		return criteria.list();
	}
	
	
	

}
